<template>
  <div>
    <el-form @submit.native.prevent class="query-table-form" :inline="true" :model="params">
      <el-form-item>
        <el-input
          v-model="params.customer_name"
          placeholder="借款人/担保客户查询"
          clearable
          @change="getData()"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <select-address
          v-model="params.address_code"
          :auto-top="1"
          placeholder="地址查询"
          clearable
          @change="getData()"
        ></select-address>
      </el-form-item>
      <el-form-item>
        <el-input
          v-model="params.bank_name"
          placeholder="银行名称查询"
          clearable
          @keyup.enter.native="getData()"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <c-select
          :options="{ 1: '有', 2: '无' }"
          v-model="hasEnsureContract"
          placeholder="委托合同编号"
          clearable
          @change="resetParams"
        ></c-select>
      </el-form-item>
      <el-form-item>
        <el-button icon="el-icon-search" @click="getData()">查询</el-button>
        <el-button
          icon="el-icon-download"
          :loading="exportLoading"
          @click="exportExcel('十二大产业贷')"
        >
          导出
        </el-button>
      </el-form-item>
    </el-form>

    <c-table border v-loading="loading" class="table-sm" :columns="tableColumns" :data="tableData">
      <template v-slot:use="scope">
        <div class="text-truncate" :title="scope.row.funds_use_dir">
          {{ scope.row.funds_use_dir }}
        </div>
      </template>
      <template v-slot:mainBudiness="scope">
        <div class="text-truncate" :title="scope.row.main_business">
          {{ scope.row.main_business }}
        </div>
      </template>
    </c-table>

    <div class="query-pagination">
      <div></div>
      <el-pagination
        layout="total, prev, pager, next, jumper"
        :current-page.sync="params.index"
        :page-size="params.size"
        :total="tableCount"
        @current-change="getData"
      ></el-pagination>
    </div>

    <el-dialog
      append-to-body
      top="30px"
      width="1100px"
      :close-on-click-modal="false"
      :visible.sync="oneIndustryVisible"
    >
      <industry-credit :one-industry="oneIndustry"></industry-credit>
    </el-dialog>

    <register-edit
      :visible.sync="dialogVisible"
      @success="getData(params.index)"
      :form-data="editDetail"
    ></register-edit>
  </div>
</template>
<script>
import IndustryCredit from '@/bank/components/IndustryCredit'
import hndTableMixin from '@/credit/views/province/hnd/hndTableMixin'
import SelectAddress from '@/components/select/SelectAddress'
import RegisterEdit from '@/bank/views/hnd/RegisterEdit'
export default {
  components: {
    IndustryCredit,
    SelectAddress,
    RegisterEdit,
  },
  mixins: [hndTableMixin],
  props: {},
  data() {
    return {
      params: {
        index: 1,
        size: 10,
        customer_name: '',
        'import_status.eq': '1',
        'update_apply.lt': 5,
        'bank_code.endlike': '',
      },
      order: {
        create_time: 'desc',
      },
      tableName: 'datum_one_county_industry',
      tableColumns: [
        {
          attrs: { label: '借款人/担保客户', prop: 'customer_name', minWidth: '120px' },
          process: (v, row) => ({
            attrs: { class: 'project-history', attrs: { 'data-history': row.is_history } },
          }),
        },
        { attrs: { label: '客户类型', prop: 'org_class_name', align: 'center' } },
        {
          attrs: { label: '行业类型', prop: 'main_business', align: 'center', minWidth: '100px' },
          slot: 'mainBudiness',
        },
        { attrs: { label: '联系电话', prop: 'corp_phone', align: 'center' } },
        { attrs: { label: '贷款银行', prop: 'bank_name', align: 'center' } },
        { attrs: { label: '放款日/拟担保起始日', prop: 'loadDate', align: 'center' } },
        { attrs: { label: '到期日', prop: 'loadEndDate', align: 'center' } },
        { attrs: { label: '贷款期限', prop: 'warranty_period', align: 'center' } },
        { attrs: { label: '贷款金额/拟担保金额(万元)', prop: 'warranty_amount', align: 'center' } },
        { attrs: { label: '保证合同', prop: 'gua_contract', align: 'center' } },
        { attrs: { label: '委托担保合同', prop: 'ensure_contract', align: 'center' } },
        {
          attrs: { label: '操作', align: 'center', width: '80px' },
          operations: [
            { content: '委托担保合同', icon: 'fa fa-edit', event: this.handleEdit },
            { content: '详情', icon: 'fa fa-search', event: this.showCreditFile },
          ],
        },
      ],
      hasEnsureContract: '',

      oneIndustry: {},
      oneIndustryVisible: false,

      dialogVisible: false,
      editDetail: {},
    }
  },
  computed: {},
  watch: {},
  created() {
    this.getData()
  },
  methods: {
    resetParams(value) {
      this.params['ensure_contract.neq'] = ''
      this.params['ensure_contract.eq'] = ''
      if (!value) {
        return this.getData()
      }
      if (+value === 1) {
        this.params['ensure_contract.neq'] = `''`
      } else {
        this.params['ensure_contract.eq'] = `''`
      }
      this.getData()
    },
    dataAdapter(item) {
      item.loadDate = this.$utils.dateFormat(item.load_date, 'yyyy-MM-dd')
      item.loadEndDate = this.$utils.dateFormat(item.load_end_date, 'yyyy-MM-dd')

      return item
    },
    showCreditFile(row = {}) {
      this.oneIndustry = row
      this.oneIndustryVisible = true
    },

    handleEdit(row) {
      this.editDetail = { ...row } || {}
      this.dialogVisible = true
    },
  },
}
</script>
<style lang="scss" scoped></style>
